package kd.bos.demo_plugin.Bill;

import java.util.Calendar;
import java.util.EventObject;
import java.util.Date;

import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;

public class ReturnTime extends AbstractBillPlugIn{

    @Override
    public void propertyChanged(PropertyChangedArgs e) {

        String fieldkey = e.getProperty().getName();
        //this.getView().showSuccessNotification(fieldkey);
        //this.getView().showSuccessNotification("02");

        if ("comt_borrow_user".equals(fieldkey)) {//如果修改借阅人字段
            

            DynamicObject base = (DynamicObject)this.getModel().getValue("comt_borrow_user"); //获取借阅人用户基础资料字段
            String addDay = base.get("comt_borow_days").toString();//获取借阅时间长度
            this.getView().showSuccessNotification(addDay);
            Date date1 = (Date)this.getModel().getValue("comt_borrow_date");//获取借阅时间
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date1);
            //添加十天
            calendar.add(Calendar.DATE,Integer.parseInt(addDay));//计算归还时间
            Date returntime = calendar.getTime();
            this.getView().showSuccessNotification(returntime.toString());
            this.getModel().setValue("comt_datefield",returntime);
        }
    }
}
